package com.jingdianjichi.subject.application.controller;

import com.jingdianjichi.subject.api.client.AuthFeignClient;
import com.jingdianjichi.subject.api.dto.AuthUserDTO;
import com.jingdianjichi.subject.common.entity.Result;
import com.jingdianjichi.subject.infra.rpc.util.LoginUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Slf4j
public class TestController {

    @Autowired
    private AuthFeignClient authFeignClient;

    @RequestMapping("test")
    public Result<String> test() {
        log.info("测试网关请求是否正确携带用户信息,当前登录用户ID:{}", LoginUtil.getLoginId());
        // 测试服务间调用
        AuthUserDTO authUserDTO = new AuthUserDTO();
        authUserDTO.setUserName(LoginUtil.getLoginId());
        Result<AuthUserDTO> result = authFeignClient.getUserInfo(authUserDTO);
        if (result.getSuccess()) {
            log.info("测试服务间调用,获取用户信息成功,用户名称:{},用户信息:{}", result.getData().getUserName(), result.getData());
        }
        return Result.ok(result);
    }
}
